package exeption;

public class Person {
    private int age;
    public int getAge() {
        return age;
    }

    public void setAge(int age) throws IllegalAgeException {
        this.age = age;
        if(age<0||age >100){
            //throw执行后，方法剩余代码就不会执行了
//            throw new RuntimeException("年龄超出了范围");
            //除了RuntimeException这类异常外，剩下抛出任何异常都要求必须在方法上声明该异常的抛出
//            throw new Exception("年龄超出了范围");
            throw new IllegalAgeException("年龄超出了范围");
        }
    }


}
